package com.lyc.controller;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/upload")
public class UploadContrller {

    @RequestMapping(value = "/upload_img",method = RequestMethod.POST)

    public Map updaload(@RequestBody MultipartFile file) throws Exception{

        //文件名
        String filename = file.getOriginalFilename();
        //路径+文件名

        String pathname="E:\\HammerMall111\\src\\main\\webapp\\static\\image\\  "+filename;
        File file1=new File(pathname);
        FileOutputStream fo = new FileOutputStream(file1) ;
        fo.write(file.getBytes());
        fo.flush();
        fo.close();
        Map<String,String> map=new HashMap();
        map.put("result","true");
        String[] statics = pathname.split("webapp");
        System.out.println(statics);
        map.put("imgpath",statics[1]);
        return map;
    }
}
